﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using SpectrumAnalyser.ModelObjects;

namespace SpectrumAnalyser.Shell.Converters
{
    public class PeaksToElementsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                var peaks = ((ObservableCollection<Peak>) value).ToList();
                var res = new List<ChemicalElement>();
                foreach (var peak in peaks.Where(x=>x.IsVisible))
                {
                    res.AddRange(peak.MatchedChemicalElements);
                }
                return new ObservableCollection<ChemicalElement>(res);
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}